<?php

class Halls_Thumb_DeleteAction extends SrsHallsBaseAction
{
	public function getCredentials()
	{
		return 'halls.thumbs';
	}

	public function executeWrite(AgaviRequestDataHolder $rd)
	{
    $path = AgaviConfig::get('core.uploads_dir') . '/halls/' . (int)$rd->getParameter('id', 0) . '/';

    foreach ($rd->getParameter('images', array()) as $image)
    {
      $this->deleteImage($path, $image);
    }

    return 'Success';
	}

  private function deleteImage($path, $image)
  {
    $image = substr(strrchr($image, '/'), 1);

    $imageFile = $path . $image;

    if (file_exists($imageFile)) unlink($imageFile);

    $thumbFile = $path . 'thumb_' . $image;

    if (file_exists($thumbFile)) unlink($thumbFile);
  }
}